<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: black;
        }

        .box {
            position: relative;
            width: 1000px;
            height: 42px;
            margin: 50px auto;
            background: white url(download.png) no-repeat right;
        }

        .box>ul {
            position: absolute;
            list-style: none;
            z-index: 10;
        }

        .box>ul>li {

            float: left;
            width: 83px;
            height: 42px;
            line-height: 42px;
            text-indent: 10px;

        }

        .box>ul>li>a {
            text-decoration: none;
            color: black;
        }

        .box>span {
            position: absolute;
            top: 0;
            left: 0;
            width: 83px;
            height: 42px;
            background: url(download.gif) no-repeat;
        }
    </style>
</head>

<body>
    <div class="box">
        <ul>
            <li><a href="#">新闻首页</a></li>
            <li><a href="#">新闻首页</a></li>
            <li><a href="#">新闻首页</a></li>
            <li><a href="#">新闻首页</a></li>
            <li><a href="#">新闻首页</a></li>
            <li><a href="#">新闻首页</a></li>
            <li><a href="#">新闻首页</a></li>
            <li><a href="#">新闻首页</a></li>
        </ul>
        <span id="cloud"></span>
    </div>
</body>
<script>
    
        var lis = document.querySelectorAll("li");
        var cloud = document.querySelector('#cloud');
        var targer = 0;
        var leader = 0;
        var current = 0;//当前点击的位置
        lis.forEach((item, index) => {
            //移动事件
            item.onmouseover = function () {
                targer = this.offsetLeft
            }
            //点击事件
            item.onclick = function () {
                //目标值 赋值给当前点击的位置
                current = targer
            }
            //离开事件
            item.onmouseout = function(){
                //上次点击的位置赋值给目标值  回到上一次点击的位置
                
                targer = current
            }
        })
        function fn() {
            leader = leader + (targer-leader) / 10
            cloud.style.left = leader +'px'
        }
        setInterval(fn,30)
    //     var lis = document.querySelectorAll('li')
    // var cloud = document.querySelector('#cloud')
    // var target = 0
    // var leader = 0
    // var current = 0 //当前点击的位置
    // lis.forEach((item,index)=>{
    //     item.onmouseover = function(){
    //         // console.log(this.offsetLeft);
    //         target = this.offsetLeft
    //     }

    //     item.onclick = function(){
    //         current = target
    //     }

    //     item.onmouseout = function(){
    //         target = current
    //     }
    // })

    // function fn(){
    //     leader = leader + (target - leader )/10
    //     cloud.style.left = leader +'px'
    // }
    // setInterval(fn,30)

</script>

</html>